package org.za.communication.message;

import java.nio.charset.Charset;

import org.apache.mina.core.buffer.IoBuffer;
import org.za.communication.core.util.ZipUtil;

public class TxlMessage extends BaseMessage {
	
	private String txlc;
	private byte[] key = new byte[4];
	

	public TxlMessage() {
		super();
		this.msgId = 0x03;
	}

	public byte[] getKey() {
		return key;
	}

	public void setKey(byte[] key) {
		this.key = key;
	}

	public String getTxlc() {
		return txlc;
	}

	public void setTxlc(String txlc) {
		this.txlc = txlc;
	}

	@Override
	public IoBuffer getData() {
		try {
			buf = IoBuffer.allocate(2).setAutoExpand(true);
			buf.putUnsignedShort(this.getMsgId());
			buf.put(key);
			int length = (new ZipUtil().zip(txlc.getBytes("utf-8"))).length;
			buf.putInt(length);
			buf.put(new ZipUtil().zip(txlc.getBytes("utf-8")));
			buf.flip();
			return buf;
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public void setData(IoBuffer buf) {
		// TODO Auto-generated method stub

	}

}
